package com.b1502.store2.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.b1502.store2.R;
import com.b1502.store2.model.InformationData;
import com.b1502.store2.util.ImageLoaderUtils;
import com.b1502.store2.util.UrlUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import static com.nostra13.universalimageloader.core.assist.ImageScaleType.EXACTLY_STRETCHED;

/**
 * Created by hasee on 2017/2/28.
 */

public class NewsItemAdapter extends BaseAdapter{

    Context context;
    InformationData[] informationDatas = new InformationData[]{};
    public NewsItemAdapter( InformationData[] informationDatas,Context context) {
        this.context = context;
        this.informationDatas = informationDatas;
    }

    @Override
    public int getCount() {

        return informationDatas.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context,R.layout.item_news_listview,null);
        TextView tv_news_item = (TextView) convertView.findViewById(R.id.tv_news_item);
        ImageView iv_news_item = (ImageView) convertView.findViewById(R.id.iv_news_item);
        tv_news_item.setText(informationDatas[position].Title);
        Log.i("imageUrl::",""+UrlUtil.getImageUrl(informationDatas[position].ImgUrl));
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .imageScaleType(EXACTLY_STRETCHED)
                .showImageForEmptyUri(R.mipmap.ic_launcher)         //没有图片资源时的默认图片
                .cacheInMemory(true)                                    //启用内存缓存
                .cacheOnDisk(true).build();                               //启用外存缓存
        ImageLoaderUtils.initOptions();
        ImageLoader.getInstance().displayImage(UrlUtil.getImageUrl(informationDatas[position].ImgUrl),iv_news_item,options);
        return convertView;
    }
}
